package ch02 {
	/**
	 * 寻找行为、避开行为同时使用
	 * 例子二，机车A同时寻找机车B和避开机车C，机车B同时寻找机车C和避开机车A，
	 * 机车C同时的寻找机车A和避开机车B。
	 * 这三辆机车会因为追捕各自的目标而形成一个圆。
	 * @author jianping.shenjp
	 */
	import ch02.com.foed.SteeredVehicle;
	import ch02.com.foed.Vector2D;
	import ch02.com.foed.Vehicle;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	public class SeekFleeTest2 extends Sprite {
		private var _vehicleA:SteeredVehicle;
		private var _vehicleB:SteeredVehicle;
		private var _vehicleC:SteeredVehicle;

		public function SeekFleeTest2(){
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			_vehicleA = new SteeredVehicle(0xFF0000);
			_vehicleA.position = new Vector2D(200, 200);
			_vehicleA.edgeBehavior = Vehicle.BOUNCE;
			addChild(_vehicleA);
			_vehicleB = new SteeredVehicle(0x00FF00);
			_vehicleB.position = new Vector2D(400, 200);
			_vehicleB.edgeBehavior = Vehicle.BOUNCE;
			addChild(_vehicleB);
			_vehicleC = new SteeredVehicle(0x0000FF);
			_vehicleC.position = new Vector2D(300, 260);
			_vehicleC.edgeBehavior = Vehicle.BOUNCE;
			addChild(_vehicleC);
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		private function onEnterFrame(event:Event):void {
			_vehicleA.seek(_vehicleB.position);
			_vehicleA.flee(_vehicleC.position);
			_vehicleB.seek(_vehicleC.position);
			_vehicleB.flee(_vehicleA.position);
			_vehicleC.seek(_vehicleA.position);
			_vehicleC.flee(_vehicleB.position);
			_vehicleA.update();
			_vehicleB.update();
			_vehicleC.update();
		}
	}

}